package com.cad3d.filemanager.action;

import java.util.List;
import java.io.Serializable;

import com.cad3d.filemanager.dao.User;
import com.cad3d.filemanager.dbutils.UserTableTool;
import com.cad3d.filemanager.utils.StringUtils;
import com.opensymphony.xwork2.ActionSupport;

public class EditUserAction extends ActionSupport {
	
	private List<User> listUsers = null;
	private User user = new User();

	public String doEditUser() {
		if (UserTableTool.getInstance().updateUser(user)) {
			listUsers = UserTableTool.getInstance().getAllUsers();
			return "success";
		} else {
			return "error";
		}
	}
	
	public void validate() {
		if (StringUtils.isNullOrEmpty(user.getUsername())) {
			addFieldError("user.username", getText("errors.userreq"));
		} else if (StringUtils.isNullOrEmpty(user.getPassword())) {
			addFieldError("user.password", getText("errors.passreq"));
		} else if (StringUtils.isNullOrEmpty(user.getFullName())) {
			addFieldError("user.password", getText("errors.fullnamereq"));
		}
	}

	public List<User> getListUsers() {
		return listUsers;
	}

	public void setListUsers(List<User> listUsers) {
		this.listUsers = listUsers;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
}
